package com.example.kajinka.readbook;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);//加载主窗体
        Log.d("readBook", "onCreateMainActivity");//打印日志
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new ButtonListener());//设置按钮的监听事件
    }

    /**
     * 添加菜单
     *
     * @param menu
     * @return
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);//设置外部menu文件
        return true;
    }

    /**
     * 给菜单添加响应时间
     *
     * @param item
     * @return
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.add_item:
                Toast.makeText(MainActivity.this, "add_item", Toast.LENGTH_LONG).show();
                break;
            case R.id.remove_item:
                Toast.makeText(MainActivity.this, "remove_item", Toast.LENGTH_LONG).show();
                break;
            default:
                break;
        }
        return true;
    }

    class ButtonListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
//            //意图对象
//            Intent intent = new Intent();
//            intent.setClass(MainActivity.this,SecondActivity.class);
//            startActivity(intent);
            Toast.makeText(MainActivity.this, "hello world", Toast.LENGTH_LONG).show();//发送helloworld信息到窗口
        }
    }
}
